<template>
	<view class="redact">
		<view class="tops">
			<view class="vis">
				<view>姓名</view>
				<view>
					<uni-easyinput :inputBorder="false" :clearable="false" v-model="clxx.name" placeholder="请输入车主名"></uni-easyinput>
				</view>
			</view>
			<view class="vis">
				<view>联系方式</view>
				<view>
					<uni-easyinput :inputBorder="false" :maxlength=11 :clearable="false" v-model="clxx.dh" placeholder="请输入联系方式"></uni-easyinput>
				</view>
			</view>
		</view>
		<!-- 保存 -->
		<view class="buts" v-if="this.hasSetText != 'add'">
			<!-- <view class="service ser1" @click="deleteCl(id)">
				<span class="sp2">删除</span>
			</view> -->
			<view class="service ser2" @click="$noMultipleClicks(refund)">
				<span class="sp2">保存</span>
			</view>
		</view>
		<view class="buts" v-if="this.hasSetText == 'add'">
			<view class="service ser2" @click="$noMultipleClicks(refund)">
				<span class="sp2">提交申请</span>
			</view>
		</view>
	</view>
</template>

<script>
	import { addPorter,bygfindById } from '@/utils/api.js';
	export default {
		data() {
			return {
				id:0,
				noClick:true,
				clxx:{
					name:'',
					dh:''
				},
				
				
				// 头部导航文字修改
				hasSetText:'add',
			}
		
		},
		onLoad(e){
			if(e.clic == 'add'){
				this.hasSetText = e.clic;
				uni.setNavigationBarTitle({
					title: "申请成为搬运"
				})
			}else{
				this.hasSetText = e.clic;
				uni.setNavigationBarTitle({
					title: "修改搬运"
				})
				this.id=e.id
				this.clDetails()
			}
		},
		methods: {
			// 获取搬运工数据
			clDetails(){
				// 获取店铺数据
				bygfindById({
					id:this.id
				}).then((res) => {
				    if (res.code === 200) {
						// console.log(res);
						this.clxx.name=res.data.name
						this.clxx.dh=res.data.telephone
				    } else {
				      uni.showToast({title:"请求错误", position: 'bottom'})
				    }
				}).catch((err) => {
					uni.showToast({title:'网络繁忙', position: 'bottom'})
				});
			},
			// 保存
			refund(){
				let obj={}
				let tkText="您确定要修改信息吗？"
				let myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
				if(this.clxx.name == ''){
					uni.showToast({title:"姓名不能为空", position: 'bottom'})
				}else if(this.clxx.dh == ''){
					uni.showToast({title:"联系方式不能为空", position: 'bottom'})
				}else if(!myreg.test(this.clxx.dh)){
					uni.showToast({title:"请输入正确的联系方式", position: 'bottom'})
				}else{
					if(this.hasSetText == 'add'){
						obj={
							name:this.clxx.name,
							telephone:this.clxx.dh
						}
						tkText="每个用户只能有一个身份，您确定要申请吗？"
					}else{
						obj={
							id:this.id,
							name:this.clxx.name,
							telephone:this.clxx.dh
						}
						tkText="您确定要修改信息吗？"
					}
					uni.showModal({
						content: tkText,
						confirmText: "确定",
						cancelText: "取消",
						success: function (res) {
							if (res.confirm) {
								console.log('用户点击确定');
								// 修改添加车辆
								addPorter(obj).then((res) => {
								    if (res.code === 200) {
								      console.log(res);
									  // this.clData=res.data
									  uni.showToast({title:"操作成功", position: 'bottom'})
									  uni.navigateBack({
									  	delta: 1
									  });
								    } else {
								      uni.showToast({title:"请求错误", position: 'bottom'})
								    }
								}).catch((err) => {
									uni.showToast({title:'网络繁忙', position: 'bottom'})
								});
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.redact{
		padding: 10px;
		.tops{
			padding: 0 10px;
			margin-bottom: 10px;
			background: #FFFFFF;
			border-radius: 10px;
			.vis{
				height: 50px;
				border-bottom: 1px solid #F5F5F5;
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-size: 18px;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 600;
				color: $mainText;
				line-height: 22px;
				view:nth-child(2){
					width: 50%;
					::v-deep .uni-easyinput{
						.uni-easyinput__content{
							.uni-easyinput__content-input{
								.uni-easyinput__placeholder-class{
									font-size: 18px;
									font-family: PingFangSC-Regular, PingFang SC;
									font-weight: 400;
									color: #999999;
									line-height: 22px;
									text-align: right;
								}
								.uni-input-input{
									font-size: 18px;
									font-family: PingFangSC-Regular, PingFang SC;
									font-weight: 400;
									color: $mainText;
									line-height: 22px;
									text-align: right;
								}
							}
						}
					}
				}
			}
			.vis:last-child{
				border-bottom: none;
			}
			
		}
		.buts{
			width: 100%;
			position: fixed;
			bottom: 4%;
			left: 10px;
			.service{
				width: 95%;
				height: 56px;
				margin-bottom: 10px;
				border-radius: 28px;
				display: flex;
				justify-content: center;
				align-items: center;
				.sp2{
					font-size: 18px;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 600;
					color: #FFFFFF;
					line-height: 56px;
					padding: 0 5px;
				}
			}
			.ser1{
				background: #999999;
			}
			.ser2{
				background: linear-gradient(232deg, #B9D378 0%, #1B9A5D 100%);
				box-shadow: 0px 0px 10px 0px rgba(33, 156, 94, 0.5);
			}
		}
	}
</style>
